/************************************************
 * Copyright (c) 2007 ~ 2009, 
 * All rights reserved.
 * Version   : 1.0
 * Author    : lengsh@gmail.com 
 * Date      : 2008.1.2
 ***********************************************/

#ifndef _PANDA_HELPER_H______
#define _PANDA_HELPER_H______

#include <string>
#include <map>
#include <iostream>
#include <glib.h>
#include <pthread.h>
#include <string.h>
#include "define.h"
#include "Events.h"

using namespace std;

class Helper 
{
	protected:
		static Helper *_instance;
		bool  Startup(const char *filename);

	protected:
		string m_sConfFile;
                string m_sIPAcl; 
                int     m_iPort;
                int     m_iwPort;
                int     m_iThreads;
                int     m_iDefaultTimer;
                unsigned  m_iCounts;
                int m_iStartTime;

                Events *m_pEvents;
///////////
	public:
		int getPort(){ return m_iPort; }
		int getWPort(){ return m_iwPort; }
		int getThreads(){ return m_iThreads; }
                int getDefaultTimer() {  return m_iDefaultTimer;  }
		const char *getIPAcl() { return m_sIPAcl.c_str(); }

		static Helper *Instance(const char *conf = NULL);
		static void Release( bool bForce = false);
	protected:
		Helper();
		virtual ~Helper();
		int get_mem_return_info(char **wbuf, int retcode,unsigned &wsize, unsigned &wbytes);
		int do_Method(int method, char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
	public:
		int Process(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes, const char *ip);
		int ReSet_User(char *data, unsigned dlen);
		int Get_Status(char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Timer(long lt);
		int Get_Users_Graph(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Get_User_Friends(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Get_User_Num_Friends(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Get_User_Type_Friends(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Get_Friends_Friends(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
		int Get_Users_Value(char *data, unsigned dlen, char **wbuf, unsigned &wsize, unsigned &wbytes);
                bool Clear();

};


#endif 

